//
//  QCHomeCell.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/2/4.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit
import SnapKit

class QCHomeCell: UITableViewCell {
    //记录底部视图的顶部约束
    var bottomViewTopConstraint: Constraint?
    
    var statusViewModel:QCStatusViewModel?{
        didSet{
            originalView.statusViewModel = statusViewModel
            //卸载约束
//            bottomViewTopConstraint?.deactivate()
            if statusViewModel?.homeModel?.retweeted_status != nil {
                
               retweetView.statusViewModel = statusViewModel
                
               bottomView.snp.makeConstraints({ (make) in
                bottomViewTopConstraint = make.top.equalTo(retweetView.snp.bottom).constraint
               })
            retweetView.isHidden = false
                
            }else {
            bottomView.snp.makeConstraints({ (make) in
                bottomViewTopConstraint = make.top.equalTo(originalView.snp.bottom).constraint
            })
                retweetView.isHidden = true
                
            }
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style:style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI(){
        
        backgroundColor = RGB(r: 235, g: 235, b: 235)

       //添加子控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(bottomView)
        
       originalView.snp.makeConstraints ({ (make) in
        make.right.left.equalToSuperview()
        make.top.equalToSuperview().offset(8)
        })
        
        retweetView.snp.makeConstraints({ (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(originalView.snp.bottom)
        })
        
        bottomView.snp.makeConstraints({ (make) in
            make.left.right.equalToSuperview()
        bottomViewTopConstraint = make.top.equalTo(retweetView.snp.bottom).constraint
//            make.height.equalTo(35)
            make.bottom.equalToSuperview()
        })
        
        }
    
   
    //懒加载
    private lazy var originalView: QCHomeOriginalView = QCHomeOriginalView()
    private lazy var retweetView: QCHomeRetweetView = QCHomeRetweetView()
    private lazy var bottomView: QCHomeBottomView = QCHomeBottomView()

}


